import request from '@/utils/request'
// type类型
import {
  currentSpuResponseData,
  trademarkResponse,
  AllImageResponse,
  SpuSaleAttrResponse,
  allAttrResponse,
  spuData,
  SkuData,
  skuInfoResponse,
} from './type'

enum API {
  CURRENT_APU_LIST = '/admin/product/',
  // 所有品牌数据
  ALL_TRADEMARKS = 'admin/product/baseTrademark/getTrademarkList',
  // 所有image
  ALL_IMAGES = '/admin/product/spuImageList/',
  // 某一个spu下全部的销售属性
  SPU_HAS_SALE_ATTR = '/admin/product/spuSaleAttrList/',
  // 获取整个项目全部的销售属性
  SPU_ALL_ATTR = 'admin/product/baseSaleAttrList/',
  ADD_SPU = '/admin/product/saveSpuInfo/',
  UPDATE_SPU = '/admin/product/updateSpuInfo/',
  // 添加sku
  ADD_SKU = '/admin/product/saveSkuInfo/',
  // 展示添加后的sku列表展示
  SKU_INFO = '/admin/product/findBySpuId/',
  // 删除spu
  DELETE_SPU = '/admin/product/deleteSpu/',
}

// 根据三级id获取spu列表数据
export const reqCurrentSpuList = (
  page: number,
  limit: number,
  category3Id: number | string,
) => {
  return request.get<any, currentSpuResponseData>(
    API.CURRENT_APU_LIST + `${page}/${limit}/?category3Id=${category3Id}`,
  )
}

// 获取全部品牌数据
export const reqAllTradeMark = () => {
  return request.get<any, trademarkResponse>(API.ALL_TRADEMARKS)
}
// 获取全部image数据
export const reqAllImage = (spuId: number) => {
  return request.get<any, AllImageResponse>(API.ALL_IMAGES + spuId)
}
// 获取某一个spu下销售属性中所有数据
export const reqSaleAttrHasList = (spuId: number) => {
  return request.get<any, SpuSaleAttrResponse>(API.SPU_HAS_SALE_ATTR + spuId)
}

// 获取所有销售属性列表
export const reqAllSaleAttr = () => {
  return request.get<any, allAttrResponse>(API.SPU_ALL_ATTR)
}

// 添加或修改 spuData
export const reqAddOrUpdateSpu = (data: spuData) => {
  if (data.id) return request.post<any, any>(API.UPDATE_SPU, data)
  return request.post<any, any>(API.ADD_SPU, data)
}

// 添加sku
export const addSku = (data: SkuData) => {
  return request.post<any, any>(API.ADD_SKU, data)
}

// 展示sku信息
export const skuInfo = (id: number | string) => {
  return request.get<any, skuInfoResponse>(API.SKU_INFO + id)
}
// 删除spu
export const deleteCurrentSpu = (id: number | string) => {
  return request.delete<any, skuInfoResponse>(API.DELETE_SPU + id)
}
